package com.sc.passbook.mapper;

import com.sc.passbook.constant.Constant;
import com.sc.passbook.vo.User;
import com.spring4all.spring.boot.starter.hbase.api.RowMapper;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * @author sc
 * Created on  2018/9/1
 */
public class UserRowMapper implements RowMapper<User> {
    private static byte[] FAMILY_B= Constant.UserTable.FAMILY_B.getBytes();
    private static byte[] NAME= Constant.UserTable.NAME.getBytes();
    private static byte[] AGE= Constant.UserTable.AGE.getBytes();
    private static byte[] GENDER= Constant.UserTable.GENDER.getBytes();

    private static byte[] FAMILY_O= Constant.UserTable.FAMILY_O.getBytes();
    private static byte[] PHONE= Constant.UserTable.PHONE.getBytes();
    private static byte[] ADDRESS= Constant.UserTable.ADDRESS.getBytes();


    @Override
    public User mapRow(Result result, int i) throws Exception {
        User.BaseInfo baseInfo = new User.BaseInfo(
                Bytes.toString(result.getValue(FAMILY_B,NAME)),
                Bytes.toInt(result.getValue(FAMILY_B,AGE)),
                Bytes.toString(result.getValue(FAMILY_B,GENDER))
        );
        User.OtherInfo otherInfo = new User.OtherInfo(
                Bytes.toString(result.getValue(FAMILY_O,PHONE)),
                Bytes.toString(result.getValue(FAMILY_O,ADDRESS))
        );

        return new User(
                Bytes.toLong(result.getRow()),baseInfo,otherInfo
        );
    }
}
